﻿Imports System.Data.SqlClient
Imports System.Data

Partial Class Apps_report_group_user
    Inherits System.Web.UI.Page

    Protected Sub btnFilter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFilter.Click

        Try

            Dim lstDepString As String = ""
            Dim i As Integer
            Dim subString As String = ""

            For i = 0 To lstStpDepartment.Items.Count - 1
                If lstStpDepartment.Items(i).Selected Then
                    lstDepString += lstStpDepartment.Items(i).Value + ","
                End If
            Next

            If lstDepString = "" Then
                subString = "0"
            Else
                subString = lstDepString.Substring(0, lstDepString.Length - 1)
            End If

            'TODO: 
            ' Old version "../Reports/report_group_user.aspx?department_code={2}&group_user_type={0}&str_group_user_type={1}"
            Dim url = "../Reports/report_group_user2.aspx?department_code={2}&group_user_type={0}&str_group_user_type={1}"

            'Dim expire As Integer

            'If "" = txtExpire.Text Then
            '    expire = 0
            'Else
            '    expire = Integer.Parse(txtExpire.Text)
            'End If

            'group_user_password_expire={0}&
            'str_group_user_password_expire={3}&
            'group_user_status={2}&
            'str_group_user_status={5}&
            '&str_department_code={3}

            'expire,
            'ddlStatus.SelectedValue,
            'expire,
            'HttpUtility.UrlEncode(ddlStatus.SelectedItem.Text),
            'ddlStpDepartment.SelectedValue
            'HttpUtility.UrlEncode(ddlStpDepartment.SelectedItem.Text)

            url = String.Format(url, _
                                 ddlCategory.SelectedValue, _
                                 HttpUtility.UrlEncode(ddlCategory.SelectedItem.Text), _
                                 subString)

            Dim script = String.Format(" window.open('{0}','_blank'); ", url)

            ScriptManager.RegisterStartupScript( _
            Me, _
            Me.GetType(), _
            Guid.NewGuid().ToString(), _
           script, _
            True _
            )
        Catch ex As Exception
            GenericHelper.ShowAlert(Me, ex.Message)
        End Try

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        lstStpDepartment.Items.Item(0).Value = 0
        lstStpDepartment.Items.Item(0).Text = "ทั้งหมด"

    End Sub

    Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
        Dim BreadCrumpBG As HtmlControl = Page.Master.FindControl("tdBreadCrump")
        Dim BreadCrump As Literal = Page.Master.FindControl("ltrBreadCrump")
        CodeMatrix.Business.GenericData.SetBreadCrump(BreadCrumpBG, BreadCrump, 46)
    End Sub
End Class
